{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. 整数类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "90 <class 'int'>\n",
      "76 <class 'int'>\n",
      "0 <class 'int'>\n",
      "十进制 118\n",
      "二进制 175\n",
      "八进制 126\n",
      "十六进制 7855\n"
     ]
    }
   ],
   "source": [
    "# 整数类型：可以表示正数、负数、0\n",
    "n1 = 90\n",
    "n2 = 76\n",
    "n3 = 0\n",
    "print(n1, type(n1))\n",
    "print(n2, type(n2))\n",
    "print(n3, type(n3))\n",
    "\n",
    "# 整数可以表示为二进制0b，十进制，八进制0o，十六进制0x\n",
    "print('十进制', 118)  # 默认为十进制\n",
    "print('二进制', 0b10101111)  # 0b二进制\n",
    "print('八进制', 0o176)  # 0o八进制\n",
    "print('十六进制', 0x1EAF)  # 0x十六进制"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. 浮点类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.14159 <class 'float'>\n",
      "3.3000000000000003\n",
      "3.3\n",
      "3.2\n"
     ]
    }
   ],
   "source": [
    "a = 3.14159\n",
    "print(a, type(a))\n",
    "n1 = 1.1\n",
    "n2 = 2.2\n",
    "print(n1 + n2)  # 可能出现小数位数不确定的情况\n",
    "\n",
    "# 解决方法：导入模块decimal\n",
    "from decimal import Decimal\n",
    "print(Decimal('1.1') + Decimal('2.2'))\n",
    "\n",
    "n1 = 1.1\n",
    "n3 = 2.1  # 可能出现小数位数不确定的情况，但是有时浮点数相加也是正常的\n",
    "print(n1 + n3)  # 结果正常，二进制底层的问题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3. 布尔类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True <class 'bool'>\n",
      "False <class 'bool'>\n",
      "2\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "f1 = True\n",
    "f2 = False\n",
    "print(f1, type(f1))\n",
    "print(f2, type(f2))\n",
    "\n",
    "# 布尔值可以转成整数计算\n",
    "print(f1 + 1)  # 2  True表示1\n",
    "print(f2 + 1)  # 1  False表示0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4. 字符串类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "人生苦短，我用python <class 'str'>\n",
      "人生苦短，我用python <class 'str'>\n",
      "人生苦短，\n",
      "我用python <class 'str'>\n",
      "人生苦短，\n",
      "我用python <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "str1 = '人生苦短，我用python' \n",
    "str2 = \"人生苦短，我用python\"\n",
    "str3 = \"\"\"人生苦短，\n",
    "我用python\"\"\"  \n",
    "str4 = '''人生苦短，\n",
    "我用python'''\n",
    "print(str1, type(str1)) # string 单引号和双引号定义的必须在一行\n",
    "print(str2, type(str2)) \n",
    "print(str3, type(str3)) # string 三引号(三个单或者三个双均可)定义的可以在连续的多行    \n",
    "print(str4, type(str4))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.6.3",
   "language": "python",
   "name": "python3.6.3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
